package com.serverdemo.application.db;

import com.serverdemo.application.common.DBOperateTypeEnum;
import com.serverdemo.application.common.DLOperatePlayerDataResponse;
import com.serverdemo.application.common.LDOperatePlayerDataRequest;
import com.serverdemo.application.common.MessageIDConst;
import com.serverdemo.core.processor.AbstractProcessor;
import com.serverdemo.core.processor.AbstractProcessorMessage;
import com.serverdemo.core.processor.ProcessorManager;

/**
 * Created by wangqiang on 2020/4/10.
 */
public class DBProcessor extends AbstractProcessor
{

    public void dispatchMessage(AbstractProcessorMessage message)
    {
        int messageID = message.getMessageID();
        switch (messageID)
        {
            case MessageIDConst.LD_OPERATE_PLAYER_DATA_REQUEST:
            {
                LDOperatePlayerDataRequest request = (LDOperatePlayerDataRequest) message;
                operatePlayerDataRequest(request);
                break;
            }
        }
    }

    public void operatePlayerDataRequest(LDOperatePlayerDataRequest request)
    {
        // TODO 数据库操作

        DLOperatePlayerDataResponse response = new DLOperatePlayerDataResponse();
        response.setResult(0);
        response.setUserName(request.getUserName());
        response.setData(null);
        response.setOperateType(request.getOperateType());

        if (request.getOperateType() == DBOperateTypeEnum.OFFLINE_SAVE_PLAYER_DATA)
        {
            return;
        }
        else
        {
            ProcessorManager.getInstance().sendMessage(ProcessorManager.getInstance().getLoginProcessor(),
                    response);
        }
    }
}